<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" id="searchInput" placeholder="Enter name to search">
    <button onclick="searchData()">Search</button>
    <div id="result"></div>
</body>


<script>

    // 假设这是你要检索的数据，通常这些数据可能来自服务器或本地存储
    var data = [
        { name: "Alice", age: 25 },
        { name: "Bob", age: 30 },
        { name: "Charlie", age: 35 }
    ];

    function searchData() {
        // 获取输入框的值
        var searchValue = document.getElementById('searchInput').value;

        // 清除之前的检索结果
        document.getElementById('result').innerHTML = '';

        // 检索数据
        var found = data.filter(function (item) {
            return item.name.toLowerCase().includes(searchValue.toLowerCase());
        });

        // 显示检索结果
        if (found.length > 0) {
            found.forEach(function (item) {
                var resultElement = document.createElement('div');
                resultElement.textContent = 'Name: ' + item.name + ', Age: ' + item.age;
                document.getElementById('result').appendChild(resultElement);
            });
        } else {
            document.getElementById('result').textContent = 'No data found.';
        }
    }
</script>
</body>

</html>
</body>

</html>